import {defineStore} from "pinia";
import {reactive} from "vue";
import {getBlogSettingsDetail} from "@/api/frontend/blogsettings.js"



export const useBlogSettingsStore = defineStore('blogSettings', () => {
        // 左边栏菜单默认宽度
        const blogSettings = reactive({
            "logo":"",
            "name":"",
            "author":"",
            "introduction": "",
            "avatar": "",
            "githubHomepage": "",
            "csdnHomepage": "",
            "giteeHomepage": "",
            "zhihuHomepage": ""
        })

        // 得到 blogSettings 信息
        function handleBlogSettings() {
            getBlogSettingsDetail().then(resp => {
                if (resp.success) {
                    const data = resp.data
                    for (const key in data) {
                        if (blogSettings.hasOwnProperty(key)) {
                            blogSettings[key] = data[key]
                        }
                    }
                }
            })

        }

        return { blogSettings, handleBlogSettings }
    },
    {
        // 开启持久化
        persist: true,
    })